package com.demo.api.system.factory;

import com.demo.api.system.service.RemoteLogService;
import com.demo.common.core.domain.SysLogininforBo;
import com.demo.common.core.domain.SysOperLogBo;
import com.demo.common.core.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 用户服务降级处理
 *
 * @author demo
 */
@Component
@Slf4j
public class RemoteLogFallbackFactory implements FallbackFactory<RemoteLogService> {

    @Override
    public RemoteLogService create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new RemoteLogService() {

            @Override
            public R<Boolean> logininfor(SysLogininforBo logininforBo, String source) {
                return R.fail("登录日志插入失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> operLocation(SysOperLogBo operLogBo, String source) {
                return R.fail("操作日志插入失败:" + throwable.getMessage());
            }
        };
    }
}
